﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using DatabaseAccessLayer;
using System.Configuration;
using SavoryBL;

namespace WebApplication
{
    public partial class Membership : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            btnSubmit.Attributes.Add("OnClick", "return ValidateCompanyMaster('" + txtFirstName.ClientID + "','" + txtLastName.ClientID + "', '" + txtContactNumber1.ClientID + "', '" + txtEmailID.ClientID + "', '" + txtConfirmEmailID.ClientID + "', '" + txtPassword.ClientID + "', '" + txtConfirmaPassword.ClientID + "','"+ddlCountry.ClientID+"','"+ddlCity.ClientID+"', '" + hdnAlertCounter.ClientID + "');");
            CountryService service = new CountryService();
            Dictionary<int,string> country = service.GetCountries();
            ddlCountry.DataSource = country;
            ddlCountry.DataValueField = "Key";
            ddlCountry.DataTextField = "Value";
            ddlCountry.DataBind();
            ddlCountry.Items.Insert(0, "Country");
           
            ((System.Web.UI.HtmlControls.HtmlGenericControl)Master.FindControl("divbreadcrum")).InnerHtml = @"<a href='default.aspx'>Home</a> > <a href='Sign-In.aspx'>Sign In / Sign Up</a> > <span>New Registration</span>";
        }
        public void btnSubmit_Click(object sender, EventArgs e)
        {
            string FirstName = txtFirstName.Text.Trim();
            string LastName = txtLastName.Text.Trim();
            string Office = txtOfficeName.Text.Trim();
            string Country = Request.Form.GetValues("ctl00$MainContent$ddlCountry")[0];
            string City = Request.Form.GetValues("ctl00$MainContent$ddlCity")[0];
            string countryCode = txtCountryCodes.Text.Trim();
            string Street = txtStreet.Text.Trim();
            string Contact1 = txtContactNumber1.Text.Trim();
            string Contact2 = txtContactNumber2.Text.Trim();
            string Phone1 = txtPhone1.Text.Trim();
            string Phone2 = txtPhone2.Text.Trim();
            string fax = txtFax.Text.Trim();
            string website = txtWebsite.Text.Trim();
            string EmailID = txtConfirmEmailID.Text.Trim();
            string Password = txtConfirmaPassword.Text;
            bool isNewlatter = chkNewsLatter.Checked;

            SavoryUserDetails savoryUserDetails = new SavoryUserDetails();
            var Result1 = savoryUserDetails.AddUser(rdoOption.SelectedItem.Text, FirstName, LastName, Office, Phone1, Phone2, Contact1, Contact2, EmailID, Password, Country, City, 0, isNewlatter, website, fax, Street);
            int Result = 0;
            //int Result = clsUser.MemberShipUserStep1(rdoOption.SelectedItem.Text,FirstName, LastName,Office, Country,City, Contact1, Contact2,Phone1,Phone2,fax,website,
            //EmailID, Password, isNewlatter);
            if (Result > 0)
            {
                Session["EmilID"]= EmailID;
                Session["FirstName"] = FirstName;
                Session["LastName"] = LastName;
                if (rdoOption.SelectedItem.Value == "1")
                {
                    Response.Redirect("Membership-Step2.aspx?ID="+Result);
                }
                else if (rdoOption.SelectedItem.Value == "2")
                {
                    Response.Redirect("Company-Registration.aspx?ID=" + Result);
                }
                else
                {
                    Response.Redirect("Membership-Complete.aspx?ID=" + Result);
                }

                //string MailContent = File.ReadAllText(Server.MapPath("signup-email.html"));
                //MailContent = MailContent.Replace("####", "http://realestate-contracting.com" + "/NonMemberActivation.aspx?ID=" + Result);
                //Utility.sendMail(EmailID, "Please activate your account", MailContent);
                //Utility.sendMail(ConfigurationManager.AppSettings["AdminEmail"].ToString(), "Non Member User Registration", "A new " + FirstName + " " + LastName + " has current registered in RealStudio");
                //Response.Redirect("Thanks.aspx");
            }
            if (Result == -2)
            {
                lblMessage.Text = "You are already existing user. Please click to forget password for retriving your password.";
                Response.Redirect("Thanks.aspx");
            }


            
        }
    }
    
}